package com.aidex.biz.controller;

import java.util.List;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.DocModel;
import com.aidex.biz.service.DocModelService;
import com.aidex.common.utils.SecurityUtils;

/**
 * 文件模版Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/biz/bizDocModel")
public class DocModelController extends BaseController
{
    @Autowired
    private DocModelService docModelService;

    /**
     * 查询文件模版列表
     */
    @GetMapping("/list")
    public R<PageInfo> list(DocModel docModel, HttpServletRequest request, HttpServletResponse response)
    {

        docModel.setPage(new PageDomain(request, response));
        return R.data(docModelService.findPage(docModel));
    }

    /**
     * 获取文件模版详细信息
     */
    @GetMapping(value = "/{id}")
    public R<DocModel> detail(@PathVariable("id") String id)
    {
        return R.data(docModelService.get(id));
    }

    /**
     * 新增文件模版
     */
    @Log(title = "文件模版", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  DocModel docModel)
    {
        return R.status(docModelService.save(docModel));
    }

    /**
     * 修改文件模版
     */
    @Log(title = "文件模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated DocModel docModel)
    {
        return R.status(docModelService.save(docModel));
    }


    /**
     * 删除文件模版
     */
    @Log(title = "文件模版", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(docModelService.deleteDocModelByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(docModelService.findMaxSort(new DocModel()));
    }

    /**
     * 导出文件模版列表
     */
    @Log(title = "文件模版", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(DocModel docModel)
    {


        List<DocModel> list = docModelService.findList(docModel);
        ExcelUtil<DocModel> util = new ExcelUtil<DocModel>(DocModel.class);
        return util.exportExcel(list, "文件模版数据");
    }

}
